<?php
require_once("library/initialize.php");
require_once("library/user-action.php");
require_once("library/admin-action.php");

function return_last_page(){
	
switch($_SESSION['where']){
case 'admin': {
	
	switch ($_SESSION['view']) {
	case 'users': {
		header("Location: admin.php?view=users&page={$_SESSION['page']}"); break;}
	case 'edit': {
		header("Location: admin.php?view=entries&id={$_SESSION['page']}"); break;}
	// entries
	default: {
		header("Location: admin.php?view=entries&page={$_SESSION['page']}"); break;}
	}
	break;}
	
// user
default: {
	switch ($_SESSION['view']) {
	case 'comments': {
		header("Location: main.php?view=comments&page={$_SESSION['page']}"); break;}
	case 'entry': {
		header("Location: main.php?view=entry&id={$_SESSION['id']}"); break;}
	// home
	default: {
		header("Location: main.php?view=home&page={$_SESSION['page']}");}
	}}
}}

initialize('');
switch ($_GET['do']) {
	case 'logout': 		{user_logout(); break;}
	case 'login': 		{user_login(); break;}
	case 'register': 	{user_register(); break;}
	case 'comment': 	{if (check_permission('user')) {store_comment();} break;}
	case 'edit_entry': 	{if (check_permission('admin')){store_entry();} break;}
	case 'del_entry': 	{if (check_permission('admin')){del_entry();} break;}
	case 'del_user': 	{if (check_permission('admin')){del_user();} break;}
}
return_last_page();

?>